package com.checkcode.jcaptcha;

import com.octo.captcha.module.servlet.image.SimpleImageCaptchaServlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SubmitActionServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html; charset=UTF-8");
		//获取输入框的值
		String userCaptchaResponse = request.getParameter("japtcha");
		//判断是否正确
		boolean captchaPassed = SimpleImageCaptchaServlet.validateResponse(request, userCaptchaResponse);
		if (captchaPassed)
			response.getWriter().write("captcha passed");
		else {
			response.getWriter().write("captcha failed");
		}
		response.getWriter().write("<br/><a href='jcaptcha.jsp'>Try again</a>");
	}
}